package com.ruanyun.modular.ry.controller;

import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import com.ruanyun.base.pojo.node.ZTreeNode;
import com.ruanyun.base.pojo.page.LayuiPageInfo;
import com.ruanyun.modular.admin.entity.TBasicinfo;
import com.ruanyun.modular.ry.entity.TDict;
import com.ruanyun.modular.ry.model.params.TDictParam;
import com.ruanyun.modular.ry.service.TDictService;
import com.ruanyun.modular.ry.vo.req.TDictReqVo;
import com.ruanyun.modular.ry.vo.resp.TDictRespVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


/**
 * 数据字典表控制器
 *
 * @author 刘耀
 * @Date 2020-12-15 13:45:32
 */
@Controller
@RequestMapping("/tDict")
public class TDictController extends BaseController {

    private String PREFIX = "/dict";

    @Autowired
    private TDictService tDictService;

    /**
     * 跳转到主页面
     *
     * @author 刘耀
     * @Date 2020-12-15
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/dict.html";
    }

    /**
     * 新增页面
     *
     * @author 刘耀
     * @Date 2020-12-15
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/dict_add.html";
    }

    /**
     * 编辑页面
     *
     * @author 刘耀
     * @Date 2020-12-15
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/dict_edit.html";
    }

    /**
     * 新增接口
     *
     * @author 刘耀
     * @Date 2020-12-15
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(TDictParam TDictParam) {
        return this.tDictService.addItem(TDictParam);
    }

    /**
     * 编辑接口
     *
     * @author 刘耀
     * @Date 2020-12-15
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(TDictParam TDictParam) {
        this.tDictService.update(TDictParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author 刘耀
     * @Date 2020-12-15
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(TDictParam TDictParam) {
        this.tDictService.delete(TDictParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author 刘耀
     * @Date 2020-12-15
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(TDictParam TDictParam) {
        TDict detail = this.tDictService.getById(TDictParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author 刘耀
     * @Date 2020-12-15
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(TDictParam TDictParam) {
        return this.tDictService.findPageBySpec(TDictParam);
    }

    /**
     * 获取部门的tree列表，ztree格式
     *
     * @author administrator
     * @Date 2018/12/23 4:56 PM
     */
    @RequestMapping(value = "/tree")
    @ResponseBody
    public List<ZTreeNode> tree() {
        List<ZTreeNode> tree = this.tDictService.tree();
        tree.add(ZTreeNode.createParent());
        return tree;
    }

//    /**
//     * 获取某个类型下字典树的列表，ztree格式
//     *
//     * @author administrator
//     * @Date 2018/12/23 4:56 PM
//     */
//    @RequestMapping(value = "/ztree")
//    @ResponseBody
//    public List<ZTreeNode> ztree(@RequestParam("categoryId") Long categoryId) {
//        return this.tDictService.categoryTreeList(categoryId);
//    }

    /**
     * 查询列表
     *
     * @author conan
     * @Date 2020-11-27
     */
    @ResponseBody
    @RequestMapping("/findPage")
    public LayuiPageInfo findPage(TDictReqVo tDictReqVo) {
        return this.tDictService.findPage(tDictReqVo);
    }


    /**
     * 查询列表
     *
     * @author zs
     * @Date 2021-04-16
     */
    @ResponseBody
    @RequestMapping("/pollutantsTypeList")
    public List<TDictRespVo> getPollutantsTypeList() {
        return this.tDictService.getPollutantsTypeList();
    }

}


